package com.ruoyi.medmanage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.medmanage.domain.MedicalInfo;
import com.ruoyi.medmanage.service.IMedicalInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药物信息
 Controller
 *
 * @author y
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/medmanage/medinfo")
public class MedicalInfoController extends BaseController
{
    @Autowired
    private IMedicalInfoService medicalInfoService;

    /**
     * 查询药物信息列表
     */
    @PreAuthorize("@ss.hasPermi('medmanage:medinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalInfo medicalInfo)
    {
        startPage();
        List<MedicalInfo> list = medicalInfoService.selectMedicalInfoList(medicalInfo);
        return getDataTable(list);
    }

    /**
     * 导出药物信息列表
     */
    @PreAuthorize("@ss.hasPermi('medmanage:medinfo:export')")
    @Log(title = "药物信息", businessType = BusinessType.EXPORT)
            @PostMapping("/export")
            public void export(HttpServletResponse response, MedicalInfo medicalInfo)
    {
        List<MedicalInfo> list = medicalInfoService.selectMedicalInfoList(medicalInfo);
        ExcelUtil<MedicalInfo> util = new ExcelUtil<MedicalInfo>(MedicalInfo.class);
        util.exportExcel(response, list, "药物信息数据");
    }

    /**
     * 获取药物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('medmanage:medinfo:query')")
    @GetMapping(value = "/{medId}")
    public AjaxResult getInfo(@PathVariable("medId") Integer medId)
    {
        return AjaxResult.success(medicalInfoService.selectMedicalInfoByMedId(medId));
    }

    /**
     * 新增药物信息
     */
    @PreAuthorize("@ss.hasPermi('medmanage:medinfo:add')")
    @Log(title = "药物信息", businessType = BusinessType.INSERT)
            @PostMapping
            public AjaxResult add(@RequestBody MedicalInfo medicalInfo)
            {
            return toAjax(medicalInfoService.insertMedicalInfo(medicalInfo));
            }

    /**
     * 修改药物信息
     */
    @PreAuthorize("@ss.hasPermi('medmanage:medinfo:edit')")
    @Log(title = "药物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalInfo medicalInfo)
    {
        return toAjax(medicalInfoService.updateMedicalInfo(medicalInfo));
    }

    /**
     * 删除药物信息
     */
    @PreAuthorize("@ss.hasPermi('medmanage:medinfo:remove')")
    @Log(title = "药物信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{medIds}")
    public AjaxResult remove(@PathVariable Integer[] medIds)
    {
        return toAjax(medicalInfoService.deleteMedicalInfoByMedIds(medIds));
    }
}
